package com.tiger.common.utils;

import com.tiger.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

/**
 * 编码类redis初始化
 *
 * @author standard
 */
@Component("Code")
public class Code {

    @Autowired
    private RedisCache redisCache;

    public static DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy");

    //redis key通过时间区分哪一天的标识
    public static String date = LocalDate.now().format(fmt);

    /**
     * 初始化编码
     */
    public void initializeCode() {
        //设备资料、文档、隐患随手拍、巡检隐患、巡检计划、其他任务、开项管理、作业指导书、施工任务、施工检修、隐患待处理、巡检任务、巡检模板、人员管理 工作票 承包商 工作票模板 工序模板 标签库 取样任务,风险管理
        String[] signs = {"sbzl", "wd", "yhssp", "xjyh", "xjjh", "qtrw", "kxgl", "zyzds", "sgrw", "sgjx", "yhdcl", "xjrw", "xjmb", "rygl", "gzp", "cbs", "mb-gzp", "gx", "bq","qyrw","fxgl"};
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");
        date = LocalDate.now().format(fmt);
        for (String sing : signs) {
            redisCache.setCacheObject(date + sing, 1, 1440, TimeUnit.MINUTES);
//            redisCache.setCacheObject(date + sing, 1);
        }
    }

    /**
     * app生成隐患编码
     */
    public void initializeAppCode() {
        //隐患随手拍、巡检隐患
        String[] signs = {"yhssp", "xjyh"};
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");
        date = LocalDate.now().format(fmt);
        for (String sing : signs) {
            redisCache.setCacheObject(date + sing, 1, 1440, TimeUnit.MINUTES);
        }
    }

    public void aa() {
        System.out.println(redisCache.keys("*"));
    }

}

